 <#import "inc/macro-page.html" as panel>
<#import "macro-filter-card-box.html" as seachpanel>
<#escape x as x?html>
<@panel.header "关键岗位轮岗混岗预警" "">
</@panel.header>
<@panel.body>
<!-- Bread crumb -->
<div class="row page-titles">
    <div class="col-md-5 align-self-center">
        <h3>关键岗位轮岗混岗预警</h3> </div>
    <div class="col-md-7 align-self-center">
        <div class="page-nav-bar">
           <button class="btn btn-info btn-click-bind" data-sign="11">轮岗预警</button>
           <button class="btn btn-inverse btn-click-bind" data-sign="12" disabled>混岗预警</button>
        </div> 
    </div>
</div>
<!-- End Bread crumb -->
<!-- Container fluid  -->
<div class="container-fluid">
    <!-- Start Page Content -->                
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
 				<div class="custom-card-header quick-bar">
					<div class="hint">混岗预警</div>
					<@seachpanel.filterbox></@seachpanel.filterbox>
					    <button id="id-export-file" type="button" class="btn btn-dark btn-outline btn-sm m-l-10" title="导出"><i class="fa fa-share-square-o"></i></button>
					</div>                	
                <div class="card-body">
              <!-- 
              <div class="row m-t-20">
                 <div class="col-lg-12">
                    <div class="row">
                     	<div class="col-md-3">
                     		<select class="form-control">
                     			<option value="">请选择单位</option>
                     		</select>
                     	</div>
                     	<div class="col-md-3">
                     		<select class="form-control">
                     			<option value="">请选择部门</option>
                     		</select>
                     	</div>
                     	<div class="col-md-3">
                     		<select class="form-control">
                     			<option value="">请选择专业</option>
                     		</select>
                     	</div>
                     	<div class="col-md-3">
                     		<select class="form-control">
                     			<option value="">请选择岗位</option>
                     		</select>
                     	</div>
                    </div>
                 </div>              
              </div>
              -->
                    <table id="id-user-table" class="table table-bordered m-t-30 content-center"  cellspacing="0">
                        <thead>
                            <tr>
                                <th>单位</th>
                                <th>部门</th>
                                <th>专业</th>
                                <th>班组</th>
                                <th>ERP编号</th>
                                <th>姓名</th>
                                <th>所定岗位</th>
                                <th>所混岗位</th>
                            </tr>
                        </thead>
                     </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End PAge Content -->
</div>
<!-- End Container fluid  -->
</@panel.body>
<@panel.footer>
<script type="text/javascript" src="${ROOT}/mind/js/plugins/alangyun-filterbox.js"></script>
<script type="text/javascript" src="${ROOT}/mind/js/lib/datatables/datatables.min.js"></script>
<script type="text/javascript" src="${ROOT}/mind/js/lib/datatables/jquery.dataTables.zh-CN.js"></script>
<script type="text/javascript">
    // word导出事件
    document.getElementById('id-export-file').addEventListener('click', function() {
        // Ensure echarts charts have finished rendering
        setTimeout(() => {
            var charts = document.querySelectorAll('canvas');
            charts.forEach(chart => {
                var dataURL = chart.toDataURL();
                var imgTag = '<img src="' + dataURL + '" />';
                chart.insertAdjacentHTML('beforebegin', imgTag);
                chart.style.display = 'none'; // Hide the original canvas
            });

            // Create a temporary container for the export
            var exportContainer = document.createElement('div');
            exportContainer.id = 'export-container';
            exportContainer.style.width = '100%';

            // Clone ECharts charts
            // var chartContainer = document.getElementById('id-fair-chart').cloneNode(true);
            // exportContainer.appendChild(chartContainer);


            var clonedTable = document.getElementById('id-user-table').cloneNode(true);
// 直接添加内联样式到每个th和td元素
            clonedTable.querySelectorAll('th, td').forEach(function(cell) {
                cell.style.border = '1px solid #000';
                cell.style.borderCollapse = 'collapse'; // 注意：borderCollapse是CSS属性，不能作为内联样式设置，但这里为了示例而写
                cell.style.textAlign = 'center';
            });
            exportContainer.appendChild(clonedTable);

            // Convert the export container's HTML to a Word document
            var htmlHeader = `
          <!DOCTYPE html>
          <html>
          <head>
            <style>
               table, th, td {
                   border: 1px solid #000;
                   text-align: center;
                   border-collapse: collapse;
               }
            </style>
          </head>
          <body>`;
            var htmlFooter = `
          </body>
          </html>`;
            var htmlContent = htmlHeader + exportContainer.innerHTML + htmlFooter;

            var blob = new Blob([htmlContent], { type: 'application/msword' });
            var url = URL.createObjectURL(blob);
            var a = document.createElement('a');
            a.href = url;
            a.download = '混岗预警.doc';
            a.click();
            URL.revokeObjectURL(url);

            // Clean up by removing the temporary container
            exportContainer.remove();

            // Revert changes made to the document for export
            charts.forEach(chart => {
                chart.previousSibling && chart.previousSibling.remove();
                chart.style.display = 'block'; // Restore the original canvas
            });
        }, 1000); // Adjust the timeout as needed to ensure charts have rendered
    });
$(document).ready(function(){	
	$(".btn-click-bind").click(function() {
		  var val = $(this).data("sign");
		  var ctx = "/w/pivotal";
		  if(12===val){
			  ctx = "/w/pivotal12";
		  }
		  window.location.href="${ROOT}" + ctx;
	});
	// 用户数据
	var $userTable = null;
	var dataToTableView = function(mydata){
		if(!mydata.users || mydata.users.length==0)
			return;
				
		if($userTable) {
			$userTable.fnClearTable();
			$userTable.fnDestroy();
		}
		
		$userTable = $("#id-user-table").dataTable({
		    "ordering":false,
		    "searching": false,
		    "bFilter":false,
		    "info": false,
		    "paging": false,
		    'bAutoWidth':false,
		    "bDestroy" : true,
		    "aoColumns": [
		    	{'mData': 'unit', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'depart', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'career', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'group', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'id', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'name', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'job', sWidth: '100px', defaultContent: '' },
		    	{'mData': 'otherJob', sWidth: '100px', defaultContent: '' }
		    ],	
		    "data":mydata.users
		});
		$userTable.fnDraw();
	};

    // 导出事件绑定
    // $('#id-export-file').click(function(){
    // 	var pdfCanvas = $.fn.pdfcanvas({
    // 		title: '关键岗位混岗预警',
    // 		keywords: '单位和部门：；岗位类别：'
    // 	})
    // 	pdfCanvas.addDom(document.getElementById("id-user-table"));
    // 	pdfCanvas.print();
    //
    // });
    //初始化过滤面板
    $.post('${ROOT}/w/treeNav',function(data, status){
    	if(data.code==="ok"){
			$.fn.filterBox({
				data: data.data,
				onsubmit: function(form, data){
				    $.post('${ROOT}/w/sumpPivo',data,function(data, status){
				    	if(data&& data.code === 'ok'){
				    		if(data.data) {
				        		dataToTableView(data.data);
				    		}else {
				    			toastr.error("未查到人岗适配资料");
				    		}
				    	} else {
				    		toastr.error(data?data.desc:"获取人岗适配资料失败");
				    	}
				    }, 'json');
				}
			})
    	}
    });
    //初始提取数据
    $.post('${ROOT}/w/sumpPivo',function(data, status){
    	if(data.code==="ok"){
    		dataToTableView(data.data);
    	}
    });
});
</script>
</@panel.footer>
</#escape>